package com.rms.hkpc.adapter;

import android.content.Context;
import android.view.View;

import com.rms.hkpc.R;
import com.rms.hkpc.adapter.base.BaseAdapter;
import com.rms.hkpc.adapter.base.BaseViewHolder;
import com.rms.hkpc.db.dto.WorksOrderDto;
import com.rms.hkpc.util.DateUtil;

import java.util.Date;
import java.util.List;


public class WorksOrderAdapter extends BaseAdapter<WorksOrderDto> {


    public WorksOrderAdapter(Context context, List<WorksOrderDto> mDatas, int layoutId) {
        super(context, mDatas, layoutId);
    }

    @Override
    public void convert(BaseViewHolder holder, WorksOrderDto item, final int position) {
        if (item.getParam() != null) {
            String color;
            if (item.getResult() == 0) {
                color = item.getParam().getFailCol() == null ? "#FF0000" : item.getParam().getFailCol();
            } else {
                color = item.getParam().getPassCol() == null ? "#FF0000" : item.getParam().getPassCol();
            }
            holder.setTextAndColor(R.id.tv_first, item.getName() == null ? "" : item.getName(), color);
            holder.setTextAndColor(R.id.tv_num, String.valueOf(item.getVal()), color);
        }
        holder.setTextAndColor(R.id.tv_second, item.getStatus() == null ? "" : item.getStatus().getName(),
                item.getStatus() == null ? "#333333" : item.getStatus().getColor());
        holder.setText(R.id.tv_third, DateUtil.getInstance().DateTimeToStr(item.getwAt(),"yyyy-MM-dd HH:mm:ss"));
        holder.fd(R.id.iv_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemChildrenClickListener != null) {
                    onItemChildrenClickListener.OnItemChildrenClickListener(v, position);
                }
            }
        });
    }
}
